<template>
  <div>
    <el-form class="form-container" :model="form" :rules="rules" ref="postForm" label-width="200px" v-loading="loading">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="排序：" prop="orderNums">
            <el-input size="mini" type="number" v-model="form.orderNums" placeholder="请输入小店名称，越大越靠前"
              :disabled="is_view" />
          </el-form-item>
          <el-form-item label="小店名称：" prop="name">
            <el-input size="mini" v-model="form.name" placeholder="请输入小店名称" :disabled="is_view" />
          </el-form-item>
          <el-form-item label="小店分类：" prop="shopTypeId">
            <el-select v-model="form.shopTypeId" placeholder="请选择">
              <el-option v-for="item in shopList" :key="item.id" :label="item.title" :value="item.id">
              </el-option>
            </el-select>
            <!-- <el-input size="mini" v-model="form.shopTypeId" placeholder="请输入小店名称" :disabled="is_view" /> -->
          </el-form-item>
          <el-form-item label="小店行业：" prop="shopIndustryId">
            <el-select v-model="form.shopIndustryId" placeholder="请选择">
              <el-option v-for="item in hyList" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
            <!-- <el-input size="mini" v-model="form.shopTypeId" placeholder="请输入小店名称" :disabled="is_view" /> -->
          </el-form-item>
          <el-form-item label="小店类型：" prop="sellerType">
            <!-- 连锁店 单店 -->
            <el-select v-model="form.sellerType" placeholder="请选择">
              <el-option label="收款门店" :value="1"></el-option>
              <el-option label="实体门店" :value="2"></el-option>
              <el-option label="企业连锁" :value="3"></el-option>
              <el-option label="商场百货" :value="4"></el-option>
              <!-- <el-option v-for="item in shopTypeLis" :key="item.id" :label="item.title" :value="item.id">
                                        </el-option> -->
            </el-select>
            <!-- <el-input size="mini" v-model="form.sellerType" placeholder="请输入小店名称" :disabled="is_view" /> -->
          </el-form-item>
          <el-form-item label="结算主体：" prop="form.settlementEntityId"
            v-if="form.sellerType == 3 || form.sellerType == 4">
            <!-- 连锁店 单店 -->
            <el-select v-model="form.settlementEntityId" filterable remote reserve-keyword placeholder="请输入绑定会员id"
              :remote-method="getMemberList" :loading="loading">
              <el-option v-for="item in jsztList" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择用户：" prop="memberId">
            {{ form.memberMobile }}
            <el-button type="primary" size="mini" @click="select()">选择</el-button>
          </el-form-item>
          <el-form-item label="联系人：" prop="consignee">
            <el-input size="mini" v-model="form.consignee" placeholder="" :disabled="is_view" />
          </el-form-item>
          <el-form-item label="联系电话：" prop="contactPhone">
            <el-input size="mini" v-model="form.contactPhone" placeholder="" :disabled="is_view" />
          </el-form-item>
          <!-- <el-form-item label="联系邮箱：" prop="contactEmail">
                                    <el-input size="mini" v-model="form.contactEmail" placeholder="" :disabled="is_view" />
                                </el-form-item> -->
          <!-- <el-form-item label="所在地区：" prop="contactArea">
                                    <area-select v-model="form.contactArea" @change="handleAreaChange" />
                                </el-form-item> -->
          <el-form-item label="小店地址：" prop="address">
            <el-input size="mini" v-model="form.address" placeholder="" class="input-with-select" maxlength="200"
              style="margin-bottom: 20px">
              <el-button size="mini" slot="append" icon="el-icon-search" @click="mapSearch('form')">搜索</el-button>
            </el-input>
            <map-marker :mapCenter.sync="mapCenter" :mapCity.sync="mapCity" :keyword.sync="mapSearchKeyword"
              @getPoi="getPoi" />
            点击地图标注或者输入经营地址后点击「搜索」后再选择标注点进行标注
          </el-form-item>
          <el-form-item label="营业时间：" prop="picture">
            <el-row>
              <el-col :span="4">
                <el-select v-model="startWeekday" multiple placeholder="请选择" @change="changesWeekday">
                  <el-option v-for="item in weekdays" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-col>
              <!-- <el-col :span="4">
                                                <el-select v-model="endWeekday" placeholder="请选择" @change="changeWeekday">
                                                    <el-option
                                                      v-for="item in weekdays"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value">
                                                    </el-option>
                                                  </el-select>
                                            </el-col> -->
              <el-col :span="4">
                <el-time-select :placeholder="startTime" v-model="startTime" :picker-options="{
                  start: '00:00',
                  step: '00:15',
                  end: '23:59',
                }">
                </el-time-select>
              </el-col>
              <el-col :span="4">
                <el-time-select :placeholder="endTime" v-model="endTime" :picker-options="{
                  start: '00:00',
                  step: '00:30',
                  end: '23:59',
                  minTime: startTime
                }">
                </el-time-select>
              </el-col>
            </el-row>
          </el-form-item>

          <el-form-item label="营业执照：" prop="picture">
            <pic-sel :maxNum="1" style="float:left" v-model="form.licensePicture" />
          </el-form-item>
          <el-form-item label="店主身份证：" prop="idPicture">
            <pic-sel :maxNum="2" style="float:left" v-model="form.idPicture" />
          </el-form-item>
          <el-form-item label="商户门头照：" prop="agentPicture">
            <pic-sel :maxNum="1" style="float:left" v-model="form.image" />
          </el-form-item>
          <!-- <el-form-item label="合同照：" prop="licensePicture">
                                    <pic-sel :maxNum="1" style="float:left" v-model="form.image" />
                                </el-form-item> -->
          <el-form-item label="店铺面积：" prop="shopArea">
            <el-input type="number" size="mini" class="w100" v-model="form.shopArea" placeholder="" :disabled="is_view">
              <p class="note_back" slot="suffix">m²</p>
            </el-input>
          </el-form-item>
          <el-form-item label="店员人数：" prop="shopClerks">
            <el-input type="number" size="mini" class="w100" v-model="form.shopClerks" placeholder=""
              :disabled="is_view">
              <p class="note_back" slot="suffix">人</p>
            </el-input>
          </el-form-item>
          <el-form-item label="服务费扣点：" prop="serviceRate">
            <el-input type="number" size="mini" class="w100" v-model="form.serviceRate" placeholder=""
              :disabled="is_view">
              <p class="note_back" slot="suffix">%</p>
            </el-input>
          </el-form-item>
          <el-form-item label="会员价：" prop="serviceRate">
            <el-input type="number" size="mini" class="w100" v-model="form.vipPrice" placeholder="">

            </el-input>
          </el-form-item>
          <el-form-item label="平台分佣比例：" prop="platformCommissionPercent">
            <el-input size="mini" class="w100" v-model="form.platformCommissionPercent" placeholder="">
              <p class="note_back" slot="suffix">%</p>
            </el-input>
          </el-form-item>
          <el-form-item label="合伙人分佣比例：" prop="partnerCommissionPercent">
            <el-input size="mini" class="w100" v-model="form.partnerCommissionPercent" placeholder="">
              <p class="note_back" slot="suffix">%</p>
            </el-input>
          </el-form-item>
          <!-- <el-form-item label="状态" prop="status" class="formItem">

                                    <el-radio-group v-model="form.status">
                                      <el-radio :label="2">待审核</el-radio>
                                      <el-radio :label="1">已审核</el-radio>
                                      <el-radio :label="3">被驳回</el-radio>
                                    </el-radio-group>
                                  </el-form-item>
                                  <el-form-item label="备注" prop="remark" class="formItem">
                                    <el-input v-model="form.remark" placeholder="请输入备注信息" type="textarea"></el-input>
                                  </el-form-item> -->
          <el-form-item v-if="!is_view">
            <el-button type="primary" size="mini" @click="next()" :loading="saveLoading">保存</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-dialog title="选择用户" :visible.sync="dialogMemberVisible" :close-on-click-modal="false" width="900px">
      <member-list :formData.sync="memberForm" @okSelect="okSelectMember" />
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="dialogMemberVisible = false">关闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="选择地址" :visible.sync="isShowLocation" :close-on-click-modal="false" width="600px">
      <el-row class="address_row" :gutter="20">
        <el-col :span="4">商家地址：</el-col>
        <el-col :span="20">
          <el-input v-model="form.address" id="tipinput" size="mini" placeholder="请输入地址搜索"></el-input>
        </el-col>
      </el-row>
      <el-row class="address_row">
        <el-col :span="4">经度信息：</el-col>
        <el-col :span="20">
          <el-input v-model="form.lng" size="mini" :disabled="true" placeholder="地图上选择定位后自动返显"></el-input>
        </el-col>
      </el-row>
      <el-row class="address_row">
        <el-col :span="4">纬度信息：</el-col>
        <el-col :span="20">
          <el-input v-model="form.lat" size="mini" :disabled="true" placeholder="地图上选择定位后自动返显"></el-input>
        </el-col>
      </el-row>
      <div id="map_container"></div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="isShowLocation = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  industry_category_tree,
  industry_category_detail
} from '../../api/industry';
import {
  seller_save,
  seller_detail,
  seller_order_detail
} from '../../api/seller';
// import {
//     age_list
// } from '../../utils/utils';
// import {
//     org_school_tree
// } from '../../api/org/index';
import {
  isInteger
} from '../../utils/validator'
import {
  settlementEntity
} from '@/api/store';
import {
  next_no
} from '../../api/sys';
import AreaList from '../../utils/area';
import { shopTypeListAll, shopCategoryList } from "@/api/store";
import { industry_all } from "@/api/industry";
import { useCascaderAreaData } from '@vant/area-data';
export default {
  name: 'seller-create',
  components: {
    // 'area-select': () => import('../../components/AreaSelect/index'),
    'pic-sel': () => import('../../components/PicSel/index'),
    'member-list': () => import('../../components/Member/index'),
    'map-marker': () => import('../../components/Mapper/marker'),
  },
  props: {
    formData: Object
  },
  watch: {
    formData: {
      immediate: true,
      handler(val) {
        this.currentId = val.seller_id;
        this.$nextTick(() => {
          this.$refs.postForm.resetFields();
          // this.$refs.postForm2.resetFields();
          // this.$refs.postForm3.resetFields();
          // this.$refs.postForm4.resetFields();
        });

        if (this.currentId > 0) {
          this.is_view = val.is_view;
          this.orderId = undefined;
          this.getDetail()
        } else {
          this.resetTemp();
          if (val.orderId) {
            this.currentId = undefined;
            this.orderId = val.orderId;
            this.getDetail()
          }
        }
      }
    }
  },
  data() {
    return {
      jsztList: [],
      options: useCascaderAreaData(),
      regionData: useCascaderAreaData(),
      weekdays: [
        { value: '周一', label: '周一' },
        { value: '周二', label: '周二' },
        { value: '周三', label: '周三' },
        { value: '周四', label: '周四' },
        { value: '周五', label: '周五' },
        { value: '周六', label: '周六' },
        { value: '周日', label: '周日' }
      ],
      startTime: "10:00",
      endTime: '22:00',
      startWeekday: ['周一'],
      endWeekday: '2',
      shopTypeLis: [],
      shopList: [],
      hyList: [],
      resId: "",
      isShowLocation: false,
      orderId: undefined,
      mapSearchKeyword: "",
      mapCenter: undefined,
      mapCity: undefined,
      dialogMemberVisible: false,
      memberForm: {
        is_select: true
      },
      props: { value: 'id', label: 'name', checkStrictly: true },
      categoryForm: {
        categoryIds: []
      },
      can_edit: true,
      form: {
        id: 0,
        settlementEntityId: undefined,
        orderNums: 1,
        name: undefined,
        memberName: undefined,
        remark: '',
        code: undefined,
        consignee: undefined,
        contactPhone: '',
        contactEmail: undefined,
        contactArea: undefined,
        contactAddress: undefined,
        idNumber: undefined,
        company: undefined,
        address: undefined,
        legalPerson: '',
        registerCapital: undefined,
        regDate: undefined,
        scope: undefined,
        picture: undefined,
        idPicture: undefined,
        bank: undefined,
        bankHost: undefined,
        bankAccount: '0123456',
        vipPrice: 1,
        // categoryIds: [],
        memberId: undefined,
        memebrMobile: undefined,
        lat: undefined,
        lng: undefined,
        shopArea: undefined,
        shopClerks: undefined,
        agentPicture: undefined,
        licensePicture: undefined,
        // adCode: 1,
        serviceRate: undefined,
        shopTypeId: 0,
        shopIndustryId: 0,
        sellerType: 1,
        scope: '',
        status: 0,
        platformCommissionPercent: 10,
        partnerCommissionPercent: 2,
        countyCode: undefined,
        provinceCode: undefined,
        cityCode: undefined,
        county: undefined,
        city: undefined,
        province: undefined,


      },
      currentId: 0,
      formStatus: 'create',
      rules: {
        name: [
          {
            required: true,
            message: '请输入小店名称',
            trigger: 'blur'
          }
        ],
        consignee: [
          {
            required: true,
            message: '请输入联系人',
            trigger: 'blur'
          }
        ],
        contactPhone: [
          {
            required: true,
            message: '请输入联系电话',
            trigger: 'blur'
          }
        ],
        address: [
          {
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }
        ],
      },
      rules2: {
        idNumber: [
          {
            required: true,
            message: '请输入统一社会信用代码',
            trigger: 'blur'
          }
        ],
        company: [
          {
            required: true,
            message: '请输入企业名称',
            trigger: 'blur'
          }
        ],
        legalPerson: [
          {
            required: true,
            message: '请输入法定代表人',
            trigger: 'blur'
          }
        ],
        registerCapital: [
          {
            validator: isInteger,
            trigger: 'blur'
          }
        ],
        regDate: [
          {
            required: true,
            message: '请选择成立日期',
            trigger: 'blur'
          }
        ],
        picture: [
          {
            required: true,
            message: '请选择营业执照',
            trigger: 'blur'
          }
        ],
        idPicture: [
          {
            required: true,
            message: '请选择法人身份证',
            trigger: 'blur'
          }
        ],
      },
      rules3: {
        idNumber: [
          {
            required: true,
            message: '请输入统一社会信用代码',
            trigger: 'blur'
          }
        ],
        company: [
          {
            required: true,
            message: '请输入企业名称',
            trigger: 'blur'
          }
        ],
        legalPerson: [
          {
            required: true,
            message: '请输入法定代表人',
            trigger: 'blur'
          }
        ],
        registerCapital: [
          {
            required: true,
            message: '请输入注册资本',
            trigger: 'blur'
          }
        ],
        regDate: [
          {
            required: true,
            message: '请选择成立日期',
            trigger: 'blur'
          }
        ],
        picture: [
          {
            required: true,
            message: '请选择营业执照',
            trigger: 'blur'
          }
        ],
        idPicture: [
          {
            required: true,
            message: '请选择法人身份证',
            trigger: 'blur'
          }
        ],
      },
      rules4: {
      },
      loading: false,
      fetchSuccess: true,
      saveLoading: false,
      is_view: false,
      activeName: "0",
      prevActiveName: "0",
      tree_list: [],
      dialogFormVisible: false,
      categoryList: []
    }
  },
  created() {
    console.log(this.regionData, '地址')
    this.getShopList();
    this.getShopTypeList();
    this.getHyList()
    this.getMemberList()

  },
  methods: {
    // 搜索结算主题
    getMemberList(e) {

      if (e) {
        let data = {
          pageNum: 0,
          pageSize: 0,
          keyword: e
        }
        settlementEntity(data).then(res => {
          console.log(res)
          this.jsztList = res.data.list || []
        })
      }

    },
    changeWeekday(e) {
      // if(e<Number(this.startWeekday)){
      //     this.$message.error('结束时间不能小于开始日期')
      //     if(Number(this.startWeekday)<=6){
      //         this.endWeekday =Number(this.startWeekday)+1+''
      //     }else{
      //         this.endWeekday  = this.startWeekday
      //     }

      //     return false
      // }
      // console.log(e)
    },
    changesWeekday(e) {

      // console.log(e,this.startWeekday.join(','))
      // if(e>Number(this.endWeekday)){
      //     this.$message.error('结束时间不能小于开始日期')
      //     if(Number(e)<=6){
      //         this.endWeekday =Number(this.startWeekday)+1+''
      //     }else{
      //         this.endWeekday  = this.startWeekday
      //     }

      //     return false
      // }
    },
    //获取小店列表
    async getShopList() {
      let res = await shopTypeListAll();
      this.shopList = res.data;
      this.form.shopTypeId = res.data[0].id
    },
    //获取小店行业
    async getHyList() {
      let res = await industry_all();
      this.hyList = res.data;
      this.form.shopIndustryId = res.data[0].id
    },
    //获取小店列表
    async getShopTypeList() {
      let res = await shopCategoryList();
      this.shopTypeLis = res.data;
    },
    refreshLocation() {
      const vatlo = this;
      this.isShowLocation = true;
      var map;
      if (this.resId && this.form.lng && this.form.lat) {
        map = new AMap.Map("map_container", {
          resizeEnable: true,
          center: [this.form.lng, this.form.lat]
        });
      } else {
        map = new AMap.Map("map_container", {
          resizeEnable: true
        });
      }
      // console.log(map)
      var autoOptions = {
        input: "tipinput"
      };
      var auto = new AMap.Autocomplete(autoOptions);
      var placeSearch = new AMap.PlaceSearch({
        map: map
      }); //构造地点查询类
      // placeSearch.search(val, (status, result)=>{
      //   console.log(result)
      // });
      AMap.event.addListener(auto, "select", select); //注册监听
      function select(e) {
        placeSearch.setCity(e.poi.adcode);
        placeSearch.search(e.poi.name); //关键字查询查询
        // console.log(e,'定位信息');
        //console.log(e.poi);
        vatlo.form.lng = e.poi.location.lng;
        // vatlo.form.adCode = e.poi.adcode;
        vatlo.form.lat = e.poi.location.lat;
        vatlo.form.address = e.poi.district + e.poi.address + e.poi.name;
      }

      // AMap.event.addListener(auto, "select", select);

      AMap.plugin("AMap.Geolocation", function () {
        var geolocation = new AMap.Geolocation({
          enableHighAccuracy: true, //是否使用高精度定位，默认:true
          timeout: 10000, //超过10秒后停止定位，默认：5s
          zoomToAccuracy: true
        });
        map.addControl(geolocation);
        if (vatlo.resId) {
          var citysearch = new AMap.CitySearch();
          citysearch.getLocalCity(function (status, result) {
            if (status === "complete" && result.info === "OK") {
              if (result && result.city && result.bounds) {
                // console.log(result);
                var cityinfo = result.city;
                var citybounds = result.bounds;
                // document.getElementById('info').innerHTML = '您当前所在城市：'+cityinfo;
                vatlo.form.address = cityinfo;
                //地图显示当前城市
                map.setBounds(citybounds);
              }
            } else {
              this.$message.error(result.info);
            }
          });
        } else {
          geolocation.getCurrentPosition(function (status, result) {
            if (status == "complete") {
              onComplete(result);
            } else {
              onError(result);
            }

            //解析定位结果
            function onComplete(data) {
              console.log(data, 11111);
              vatlo.form.lng = data.position.lng;
              vatlo.form.lat = data.position.lat;
              // vatlo.form.adCode = data.addressComponent.adcode;
              vatlo.form.address =
                data.addressComponent.province +
                data.addressComponent.city +
                data.addressComponent.district +
                data.addressComponent.township +
                data.addressComponent.street +
                data.addressComponent.streetNumber;
            }

            //解析定位错误信息
            function onError(data) {
              this.$message.error("定位失败,原因：" + data.message);
              // this.getLngLatLocation()
            }
          });
        }
      });
    },
    mapSearch(formName) {
      this.mapSearchKeyword = this.form.address;
    },
    handleAreaChange() {
      this.beautyCity();
    },
    beautyCity() {
      let areaArr = this.form.contactArea.split(",");
      if (areaArr[1]) {
        for (let i in AreaList.city_list) {
          if (i == areaArr[1]) {
            this.mapCity = AreaList.city_list[i];
            // console.log(this.mapCity)
            break;
          }
        }
      }
    },
    getPoi(position) {
      let that = this
      console.log(position.address, '地图坐标')
      if (position.address) {
        let cityname = position.address.cityname
        let code = that.checkCiteCode(cityname)
        that.form.countyCode = position.address.adcode
        that.form.provinceCode = position.address.pcode
        that.form.cityCode = code
        that.form.county = position.address.adname
        that.form.city = position.address.cityname
        that.form.province = position.address.pname
      }


      this.form.lat = position.position.lat
      this.form.lng = position.position.lng
      // if(position.adCode) {
      //     this.form.adCode = position.adCode;
      // }
      // console.log(this.form.lat);
      // console.log(this.form.lng);
      // console.log(this.form.adCode);
      // console.log(point.lat + "-" + point.lng)
      console.log(this.form, '地图坐标1111')
    },
    okMemberSelect() {

    },
    checkCiteCode(name) {
      let code = ''
      if (name) {

        this.regionData.forEach(item => {
          let items = item.children
          let info = items.find(it => it.label === name)
          if (info) {
            code = info
            return
          }

        })
        console.log(code, "##############")
      }


      return code.value
    },
    select() {
      // this.memberForm = {
      //     is_select: false
      // };
      // console.log(this.memberForm);
      this.dialogMemberVisible = true;
    },
    resetTemp() {
      this.form = {
        id: 0,
        settlementEntityId: undefined,
        orderNums: 1,
        name: undefined,
        memberName: undefined,
        remark: '',
        code: undefined,
        consignee: undefined,
        contactPhone: '',
        contactEmail: undefined,
        contactArea: undefined,
        contactAddress: undefined,
        idNumber: undefined,
        company: undefined,
        address: undefined,
        legalPerson: '',
        registerCapital: undefined,
        regDate: undefined,
        scope: undefined,
        picture: undefined,
        idPicture: undefined,
        bank: undefined,
        bankHost: undefined,
        bankAccount: '0123456',
        vipPrice: 1,
        // categoryIds: [],
        memberId: undefined,
        memebrMobile: undefined,
        lat: undefined,
        lng: undefined,
        shopArea: undefined,
        shopClerks: undefined,
        agentPicture: undefined,
        licensePicture: undefined,
        // adCode: 1,
        serviceRate: undefined,
        shopTypeId: 0,
        shopIndustryId: 0,
        sellerType: 1,
        scope: '',
        status: 0,
        platformCommissionPercent: 10,
        partnerCommissionPercent: 2,
        countyCode: undefined,
        provinceCode: undefined,
        cityCode: undefined,
        county: undefined,
        city: undefined,
        province: undefined,

      };
      // next_no(4).then(response=>{
      //     this.form.code = response.data.number;
      // });
      this.can_edit = true;
    },
    leaveTab(activeName, oldActiveName) {
      if (this.form.id > 0) {
        return true;
      }
      if (this.prevActiveName == this.activeName) {
        return false;
      }

      this.prevActiveName = this.activeName
      return true;
    },
    getDetail() {
      if (this.currentId) {
        seller_detail(this.currentId).then(response => {
          this.form = response.data;
          this.form.sellerType = Number(this.form.sellerType)
          let scope = this.form.scope.split(",");
          // console.log(scope,'营业时间')
          this.startWeekday = scope.filter(item => !item.includes(':'));
          const times = scope.filter(item => item.includes(':'));
          this.startTime = times[0]
          this.endTime = times[1]
          // console.log('Weekdays:', weekdays);
          // console.log('Times:', times);
          if (this.form.lat && this.form.lng) {
            this.mapCenter = this.form.lat + "," + this.form.lng;
          } else {
            this.mapCenter = undefined;
          }
          // console.log(this.mapCenter)
          // let area = [];
          // if(this.form.provinceCode) {
          //     area.push(this.form.provinceCode);
          //     if(this.form.cityCode) {
          //         area.push(this.form.cityCode);
          //         if(this.form.countyCode) {
          //             area.push(this.form.countyCode);
          //         }
          //     }
          // }
          // this.form.contactArea = area.join(",");
          this.formStatus = "update";
          this.can_edit = true
        }).catch(() => {
          this.formStatus = ""
        });

      } else if (this.orderId) {
        seller_order_detail(this.orderId).then((res) => {
          if (res.data) {
            this.form.memberId = res.data.memberId;
            this.form.memberMobile = res.data.memberMobile;
          }
        }).catch((err) => {

        })
      }
    },
    cancel() {
      this.$emit('cancelCreate');
    },
    next() {

      if (!this.form.idPicture) {

        this.$message.error('请上传身份证照片');
        return


      } else {
        // console.log(this.form.idPicture.split(',').length)
        if (this.form.idPicture.split(',').length < 2) {
          this.$message.error('请上传身份证照片正反面');
          return
        }

      }

      this.endTime ? this.endTime : this.endTime = '22:00'
      this.startWeekday.length ? this.startWeekday : this.startWeekday = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']

      this.form.scope = this.startWeekday.join(',') + ',' + this.startTime + ',' + this.endTime

      this.form.adcode = this.form.countyCode
      this.form.adCode = this.form.countyCode
      console.log(this.form, "######################")
      // return
      this.$refs["postForm"].validate(valid => {
        if (valid) {
          //最后一步
          // this.form.provinceCode = 0;
          // this.form.cityCode = 0;
          // this.form.countyCode = 0;
          // if(this.form.contactArea) {
          //     let aa = this.form.contactArea.split(",");
          //     this.form.provinceCode = aa[0] || 0;
          //     this.form.cityCode = aa[1] || 0;
          //     this.form.countyCode = aa[2] || 0
          // }

          this.saveLoading = true;
          seller_save(this.form)
            .then(() => {
              this.saveLoading = false;
              this.$message.success(this.form.id > 0 ? "小店信息已保存" : "成功添加小店");
              this.$emit('okCreate');
            }).catch((err) => {
              this.saveLoading = false;
            })
        }
      });
    },
    prev() {
      this.prevActiveName = this.activeName
      this.activeName = "" + (parseInt(this.activeName) - 1) + "";
    },
    handleClick(tab, event) {
      // this.prevActiveName = this.activeName
      // console.log(this.prevActiveName + "-" + this.activeName)
    },
    handleSelect() {
      this.dialogFormVisible = true;
    },
    okSelect() {
      if (this.categoryForm.categoryIds && this.categoryForm.categoryIds.length > 0) {
        let id = this.categoryForm.categoryIds[this.categoryForm.categoryIds.length - 1];

        industry_category_detail(id).then((res) => {
          if (res.data) {
            let has = false;
            this.categoryList.forEach((item) => {
              if (item.id == res.data.id) {
                has = true;
                return false;
              }
            });

            if (!has) {
              this.categoryList.push(res.data)
            }
            this.dialogFormVisible = false;
          }
        }).catch((err) => {
        })
      } else {

      }
      // console.log(this.categoryForm.categoryIds)
    },
    delete_item(idx) {
      this.$confirm('确定删除这个类目吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let items = [];

          this.categoryList.forEach((item, item_idx) => {
            if (item_idx != idx) {
              items.push(item);
            }
          })

          this.categoryList = items;
        }).catch(() => { });
    },
    okSelectMember(item) {
      // if(item.roleId != 0) {
      //     this.$message.error("只能选择鲸粉");
      // } else {
      this.form.memberId = item.id;
      this.form.memberMobile = item.mobile;
      this.dialogMemberVisible = false;
      // }
      // console.log(item)
    }
  }
}
</script>
